package org.kamionowski.supreme.jobs;

import java.util.Comparator;

/**
 * Created by IntelliJ IDEA.
 * User: Marcin Kamionowski
 * Date: 11.04.11
 * Time: 23:23
 */
public class PrioritizeScanContext implements Comparator<ScanContext> {
    @Override
    public int compare(ScanContext o1, ScanContext o2) {
        int o1points = 0;
        int o2points = 0;

        if(o1.getRequest().isAdminRequest()){
            o1points += 10;
        }
        if(o2.getRequest().isAdminRequest()){
            o2points += 10;
        }

        if(o1.getRequest().getRequestCreationDate().before(o2.getRequest().getRequestCreationDate())){
            o1points += 10;
        }else{
            o2points += 10;
        }

        if(o1points == o2points){
            return 0;
        }
        return o1points < o2points ? -1 : 1;
    }
}
